﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

public partial class ChangePassword : System.Web.UI.Page
{
    eStoreDataContext db= new eStoreDataContext();
    public string mahoa(string pass)
    {
        return System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(pass.Trim(), "MD5");
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        String user = Request["user"];
        String pw = Request["pw"];
        String pw1 = Request["pw1"];
        String pw2 = Request["pw2"];
        string passmahoa = mahoa(pw);
        try
        {
            var cus = db.Customers
                .Single(c => c.CusId == user && c.Password == passmahoa);
            if (cus !=null)
            {
                String pw1mahoa = mahoa(pw1);
                cus.Password = pw1mahoa;
                db.SubmitChanges();
                Response.Write("var msg = {status:true}");
            }
            else
            {
                Response.Write("var msg = {status:false}");
            }

        }
        catch
        {
            Response.Write("var msg = {status:false}");
        }
    }
}